
import AbsControler from '../abscontroler.js'
import { LGXEnums } from '../../common/sysenum.js'
import lgxcom from '../../common/common.js'
import { CoordTRFUtil } from '../../common/tools/coordtool.js';


class PanViewControler extends AbsControler.AbsControler {
    constructor(datamanger, displayMng) {
        super(datamanger);
        this.displayMng = displayMng;
        this.m_tLastLMosDownScreenPt = new lgxcom.LGXPoint();
    }

    act2Mouse(mosEvnt, worldPos, painter) {
        let mapViewInfo = this.dataManger.getMapViewInfo();
        let screenPt = CoordTRFUtil.world2Screen(worldPos, mapViewInfo);
        if (mosEvnt.type == LGXEnums.LGXMouseMode.LMouseDown) {
            this.m_tLastLMosDownScreenPt.clone(screenPt);
        }
        else if (mosEvnt.type == LGXEnums.LGXMouseMode.mouseDrag) {
            let screenx = (screenPt.x - this.m_tLastLMosDownScreenPt.x);
            let screeny = (screenPt.y - this.m_tLastLMosDownScreenPt.y);
            screenx = Math.ceil(screenx);
            screeny = Math.ceil(screeny);
            // screenx = -20;
            // screeny = 0;
            if (screenx != 0 || screeny != 0) {
                console.log('screenx:' + screenx + ",screeny:" + screeny);
                this.displayMng.panView(painter, this.dataManger, screenx, screeny);
            }
        }
        this.m_tLastLMosDownScreenPt.clone(screenPt);
    }

    onKeyPress(painter, evt, mospos) {
        let keycode = evt.code;
        let tx = 0;
        let ty = 0;
        if (keycode == "ArrowLeft") {
            tx = -20;
        }
        else if (keycode == "ArrowRight") {
            tx = 20;
        }
        
        if (keycode == "ArrowUp") {
            ty = -20;
        }
        else if (keycode == "ArrowDown") {
            ty = 20;
        }

        if (tx != 0 || ty != 0) {
            this.displayMng.panView(painter, this.dataManger, tx, ty);
        }
    }
}

export { PanViewControler }

